#coding=utf-8
'''
Extracting a Subset of a Dictionary

 using a dictionary comprehension
 字典推导式最快
'''

prices = {
    'ACME': 45.23,
    'AAPL': 612.78,
    'IBM': 205.55,
    'HPQ': 37.20,
    'FB': 10.75
}
p1 = {key: value for key, value in prices.items() if value > 200}
print(p1)

tech_names = {'AAPL', 'IBM', 'HPQ', 'MSFT'}
p2 = {key: value for key, value in prices.items() if key in tech_names}
print(p2)

# Part2 dict() 速度不快
p3 = dict((key, value) for key, value in prices.items() if prices > 100)

# Part3
p22 = {key: prices[key] for key, value in prices.items() for key in tech_names}